<template>
	<view class="addAcc">
		<u--form labelPosition="left" labelWidth='80' :model="dataForm" :rules="rules" ref="uForm">
			<u-form-item label="账本名称:" prop="name" ref="item1">
				<u-input v-model="dataForm.name" placeholder="请输入账本名称" border="none" />
			</u-form-item>
			<u-form-item label="备注:" prop="remark" ref="item1">
				<u-input v-model="dataForm.remark" placeholder="请输入备注" border="none" />
			</u-form-item>
		</u--form>
		<view @click="submit" class="submit">提交</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataForm: {
					name: "",
					remark: '',
					userIds: [uni.getStorageSync('userInfo')._id],
					
				},

				rules: {
					name: {
						required: true,
						message: '请输入账本名称',
						trigger: ['blur', 'change']
					}
				}
			}
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.uForm.setRules(this.rules)

		},
		methods: {
			submit() {
				let _this = this;
				let data = this.dataForm
				this.$refs.uForm.validate().then(res => {
					// uni.$u.toast('校验通过')
					_this.$cloudApi.call({
						name: 'addAccount',
						data,
						success: res => {
							// uni.reLaunch({
							// 	url: '/pages/index/index'
							// })
							uni.showToast({
								title: '新增成功',
								icon: 'success',
								complete() {
									uni.navigateBack()
								}
							});
						}
					});
				}).catch(errors => {
					// 
				})
			},
		}
	}
</script>

<style scoped lang="less">
	.addAcc {
		padding: 20rpx;
		background: #fff;

		.submit {
			background: #007AFF;
			color: #fff;
			text-align: center;
			border-radius: 40rpx;
			padding: 20rpx;
			width: 94%;
			box-sizing: border-box;
			// margin-top: 140rpx;
			position: fixed;
			bottom: 50rpx;
			left: 22rpx;
		}
	}
</style>